<?php
namespace app\agent\servlet;

class UserTginfoServlet extends BaseServlet
{
	public function __construct()
	{
		parent::__construct();
	}

	/**
	* 组装查询条件
	* @param array $data
	* @return array
	*/
	public function getWhere($data = [])
	{
		$where = [];
		
		if( empty($data) )
		{
			return $where;
		}

        if( empty($data['type']) === false && empty($data['addr_code'] === false) )
        {
            switch ($data['type'])
            {
                case 1:
                    $data['province'] = $data['addr_code'];
                    break;
                case 2:
                    $data['city'] = $data['addr_code'];
                    break;
                case 3:
                    $data['area'] = $data['addr_code'];
                    break;
            }
        }

        if( empty($data['province']) === false )
        {
            $where[] = ['tginfo.province', '=', $data['province']];
        }

        if( empty($data['city']) === false )
        {
            $where[] = ['tginfo.city', '=', $data['city']];
        }

        if( empty($data['area']) === false )
        {
            $where[] = ['tginfo.area', '=', $data['area']];
        }

		if( empty($data['tgnumber']) === false )
		{
            $where[] = ['tgnumber', '=', $data['tgnumber']];
		}

		if( empty($data['truename']) === false )
		{
            $where[] = ['truename', '=', $data['truename']];
		}

		if( empty($data['telephone']) === false )
		{
            $where[] = ['telephone', '=', $data['telephone']];
		}
		
		if( isset($data['status']) && $data['status'] !== '' )
		{
			$where[] = ['status', '=', $data['status']];
		}
		
		return $where;
	}

	/**
	* 整理数据
	* @param array $data
	* @return array
	*/
	public function collating($data = [])
	{
		if( empty($data) )
		{
			return $data;
		}

		return $data;
	}
}